﻿/************************************************************************************
 *      Copyright (C) 2015 yuwei,All Rights Reserved
 *      File:
 *                Program.cs
 *      Description:
 *            主程序入口，线程相关演示示例
 *      Author:
 *                Yangxianwen
 *                
 *                
 *      Finish DateTime:
 *                2017年07月25日
 *      History:
 ***********************************************************************************/

using System;
using System.Threading;

namespace ThreadDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            {
                //非安全性的伪单例模式调用
                //var d1 = Demo.GetInstance();
                //var d2 = Demo.GetInstance();

                //Console.WriteLine("d1 == d2 {0}",object.ReferenceEquals(d1,d2));
                //Console.Read();
            }

            {
                //Demo d1 = null;
                //Demo d2 = null;
                ////多线程创建对象实例
                //var t1 = new Thread(() => { d1 = Demo.GetInstance(); });
                //var t2 = new Thread(() => { d2 = Demo.GetInstance(); });

                //t1.Start();
                //t2.Start();
                //Thread.Sleep(1000);//主线程等待子线程执行完成，为d1和d2变量赋值
                //Console.WriteLine("d1 == d2 {0}", object.ReferenceEquals(d1, d2));
                //Console.Read();
            }
            {
                for (int i = 0; i < 2; i++)
                {
                    new Action(() => { Demo.GetInstance(); }).BeginInvoke(null, null);
                }
                Console.Read();
            }
        }
    }
}
